package com.example.springmvcdemo4;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Q
 * @create 2025-05-26-18:50
 */
@RequestMapping("/user")
@RestController
public class UserController {
    //登录页面
    @RequestMapping("/login")
    public boolean login(String userName, String passWord, HttpSession session) {
        //判断是否为空
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(passWord)) {
            return false;
        }
        //验证账号
        if("zhangSan".equals(userName) && "123456".equals(passWord)) {
            //存储Session
            session.setAttribute("userName",userName);
            session.setAttribute("passWord",passWord);
            return true;
        }
        return false;
    }
    //用户主页
    @RequestMapping("/getUserInfo")
    public String getUserInfo(HttpSession session) {
        String userName = (String)session.getAttribute("userName");
        return userName;
    }
}
